// --------------
// 作者:Vitity
// --------------

namespace NICWebApi.Extensions.DynamicAPI.Options;

/// <summary>
/// 动态API配置选项
/// </summary>
public class DynamicApiOptions
{
    /// <summary>
    /// Swagger配置选项
    /// </summary>
    public SwaggerBuildOptions Swagger { get; set; } = new SwaggerBuildOptions();

    /// <summary>
    /// MiniProfiler配置选项
    /// </summary>
    public MiniProfilerOptions MiniProfiler { get; set; } = new MiniProfilerOptions();

    /// <summary>
    /// 路由配置选项
    /// </summary>
    public RoutingOptions Routing { get; set; } = new RoutingOptions();

    /// <summary>
    /// 要排除的程序集名称列表
    /// </summary>
    public string[] ExcludedAssemblies { get; set; } = new[] { "Microsoft.AspNetCore.OData" };

    /// <summary>
    /// 要包含的程序集名称列表（如果指定，则只扫描这些程序集）
    /// </summary>
    public string[] IncludedAssemblies { get; set; } = Array.Empty<string>();
}

/// <summary>
/// Swagger配置选项
/// </summary>
public partial class SwaggerBuildOptions
{
    /// <summary>
    /// 文档标题
    /// </summary>
    public string Title { get; set; } = "API Documentation";

    /// <summary>
    /// 文档版本
    /// </summary>
    public string Version { get; set; } = "v1";

    /// <summary>
    /// 文档描述
    /// </summary>
    public string Description { get; set; } = "API Description";

    /// <summary>
    /// 服务条款URL
    /// </summary>
    public string TermsOfServiceUrl { get; set; } = "https://example.com/terms";

    /// <summary>
    /// 联系人信息
    /// </summary>
    public ContactInfo Contact { get; set; } = new ContactInfo();

    /// <summary>
    /// 许可证信息
    /// </summary>
    public LicenseInfo License { get; set; } = new LicenseInfo();

    /// <summary>
    /// 是否启用Swagger UI
    /// </summary>
    public bool EnableSwaggerUI { get; set; } = true;

    /// <summary>
    /// Swagger路由前缀
    /// </summary>
    public string RoutePrefix { get; set; } = "";

    /// <summary>
    /// 虚拟路径
    /// </summary>
    public string VirtualPath { get; set; } = "";

    /// <summary>
    /// 是否启用授权
    /// </summary>
    public bool? EnableAuthorized { get; set; } = true;
}

/// <summary>
/// 联系人信息
/// </summary>
public class ContactInfo
{
    /// <summary>
    /// 联系人名称
    /// </summary>
    public string Name { get; set; } = "API Support";

    /// <summary>
    /// 联系人URL
    /// </summary>
    public string Url { get; set; } = "https://example.com/contact";

    /// <summary>
    /// 联系人邮箱
    /// </summary>
    public string Email { get; set; } = "support@example.com";
}

/// <summary>
/// 许可证信息
/// </summary>
public class LicenseInfo
{
    /// <summary>
    /// 许可证名称
    /// </summary>
    public string Name { get; set; } = "MIT";

    /// <summary>
    /// 许可证URL
    /// </summary>
    public string Url { get; set; } = "https://example.com/license";
}

/// <summary>
/// MiniProfiler配置选项
/// </summary>
public class MiniProfilerOptions
{
    /// <summary>
    /// 是否启用MiniProfiler
    /// </summary>
    public bool Enabled { get; set; } = true;

    /// <summary>
    /// 路由基础路径
    /// </summary>
    public string RouteBasePath { get; set; } = "/profiler";

    /// <summary>
    /// 是否启用MVC过滤器分析
    /// </summary>
    public bool EnableMvcFilterProfiling { get; set; } = false;

    /// <summary>
    /// 是否启用MVC视图分析
    /// </summary>
    public bool EnableMvcViewProfiling { get; set; } = false;

    /// <summary>
    /// 颜色方案
    /// </summary>
    public string ColorScheme { get; set; } = "Auto";

    /// <summary>
    /// 弹出框渲染位置
    /// </summary>
    public string PopupRenderPosition { get; set; } = "BottomLeft";

    /// <summary>
    /// 是否显示子时间
    /// </summary>
    public bool PopupShowTimeWithChildren { get; set; } = true;

    /// <summary>
    /// 是否显示琐碎信息
    /// </summary>
    public bool PopupShowTrivial { get; set; } = false;

    /// <summary>
    /// 是否启用实体框架分析
    /// </summary>
    public bool EnableEntityFrameworkProfiling { get; set; } = true;
}

/// <summary>
/// 路由配置选项
/// </summary>
public class RoutingOptions
{
    /// <summary>
    /// API路由前缀
    /// </summary>
    public string ApiRoutePrefix { get; set; } = "api";

    /// <summary>
    /// 控制器名称后缀列表，用于移除控制器名称中的这些后缀
    /// </summary>
    public List<string> ControllerNameSuffixesToRemove { get; set; } = new List<string>
    {
        "ApplicationService",
        "AppService",
        "Service",
        "Controller"
    };

    /// <summary>
    /// 是否将控制器名称复数化（添加s）
    /// </summary>
    public bool PluralizeControllerNames { get; set; } = false;

    /// <summary>
    /// 是否保持原名
    /// </summary>
    public bool KeepParameterOriginalName { get; set; } = false;

    /// <summary>
    /// 是否使用驼峰命名
    /// </summary>
    public bool UseCamelCase { get; set; } = true;

    /// <summary>
    /// 动作名称前缀列表，用于移除动作名称中的这些前缀
    /// </summary>
    public List<string> ActionNamePrefixesToRemove { get; set; } = new List<string>
    {
        "GetAll", "GetList", "Get",
        "Post", "Create", "Add", "Insert",
        "Put", "Update",
        "Delete", "Remove",
        "Patch"
    };

    /// <summary>
    /// 动作名称后缀列表，用于移除动作名称中的这些后缀
    /// </summary>
    public List<string> ActionNameSuffixesToRemove { get; set; } = new List<string> { "Async", "Service" };

    /// <summary>
    /// HTTP方法映射规则
    /// </summary>
    public Dictionary<string, string> HttpMethodMappings { get; set; } = new Dictionary<string, string>
        {
            { "Get", "GET" },
            { "GetAll", "GET" },
            { "GetList", "GET" },
            { "Query", "GET" },
            { "Find", "GET" },
            { "Post", "POST" },
            { "Create", "POST" },
            { "Add", "POST" },
            { "Insert", "POST" },
            { "Put", "PUT" },
            { "Update", "PUT" },
            { "Delete", "DELETE" },
            { "Remove", "DELETE" },
            { "Patch", "PATCH" }
        };
}